package com.tunan.lsj.id.impl;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.tunan.config.AppConfig;
import com.tunan.config.SequenceHiLoGenerator;
import com.tunan.lsj.id.IKeyGenerator;
import com.tunan.persistence.model.TSysUser;


/**
 * 业务流水号生成器
 * 
 * @author czhcc
 *
 */
@Component(value="ywlshKeyGen")
public class YwlshKeyGenerator extends AbstractGenerator implements IKeyGenerator
{

	private static SequenceHiLoGenerator hiLoGenerator = new SequenceHiLoGenerator();

	public YwlshKeyGenerator()
	{
		super();
		setParameter(null, "SEQ_YWLSH");
	}

	public String createKey(TSysUser user, Map model)
	{
		long tmpKey = hiLoGenerator.generate(sequenceName);
		DecimalFormat formatter = new DecimalFormat(AppConfig.YWLSH_FORMAT);
		String formmatKey = formatter.format(tmpKey);
		String xzq = null;
		if( user.getXzq()== null || StringUtils.isEmpty(user.getXzq()))
		{
			xzq = "00";
		}
		else
		{
			xzq = user.getXzq().substring(4);
		}
		StringBuffer sb = new StringBuffer(14).append(xzq).append(formmatKey);

		System.out.println("生成的ywlsh=" + sb.toString());
		return sb.toString();
	}
}
